commonlibsse_ng\rel\id/
mod.rs

1mod id_database;
2mod offset_to_id;
3mod relocation_id;
4mod variant_id;
5
6use std::num::NonZeroUsize;
7
8pub use self::id_database::{DataBaseError, IDDatabase};
9pub use self::offset_to_id::OffsetToID;
10pub use self::relocation_id::RelocationID;
11pub use self::variant_id::VariantID;
12
13use self::id_database::ID_DATABASE;
14use super::ResolvableAddress;
15
16/// Represents a memory mapping ID and offset.
17///
18/// This struct is used to uniquely identify a mapped memory region.
19#[repr(C)]
20#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
21pub struct Mapping {
22    /// The unique ID of the memory-mapped file.
23    pub id: u64,
24    /// The memory address offset within the mapped region.
25    pub offset: u64,
26}
27
28/// Represents different formats of the address library.
29#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
30pub enum Format {
31    SSEv1,
32    SSEv2,
33    VR,
34}
35
36/// Represents an ID that can be used to look up an address in the ID database.
37///
38/// This struct wraps a `u64` value and allows resolution of an absolute address
39/// based on the ID's corresponding offset.
40///
41/// # Example
42/// ```rust
43/// use commonlibsse_ng::rel::id::ID;
44/// use commonlibsse_ng::rel::ResolvableAddress;
45///
46/// let id = ID::new(42);
47/// let address = id.address();
48/// ```
49#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
50#[repr(transparent)]
51pub struct ID(u64);
52
53impl ID {
54    /// Creates a new `ID` instance with the given value.
55    #[inline]
56    pub const fn new(id: u64) -> Self {
57        Self(id)
58    }
59}
60
61impl ResolvableAddress for ID {
62    /// Retrieves the offset corresponding to the ID.
63    ///
64    /// # Errors
65    /// Returns an error if the ID is not found in the database.
66    #[inline]
67    fn offset(&self) -> Result<NonZeroUsize, DataBaseError> {
68        ID_DATABASE.id_to_offset(self.0)
69    }
70}